import {
    Component,
    ElementRef,
    OnInit
}
from 'angular2/core';
import {
    HTTP_PROVIDERS
} from 'angular2/http';
import {
    Bilibili
} from '../app.service';
import {
    Util
} from '../app.util.service';
import {
    PItem,
    BResult
} from '../app.model';

declare var jQuery:any;
import 'jq/danmu/danmuplayer.js';

@Component({
    selector: 'player',
    // Every Angular template is first compiled by the browser before Angular runs it's compiler
    template: require('./player.html'),
    providers: [
        Bilibili,
        Util,
        HTTP_PROVIDERS
    ]
})
export class Player {
    private player:any;
    av:BResult;
    
    constructor(public _elementRef:ElementRef,public bilibili:Bilibili){
        this.av = <BResult>{};
    }
    
    ngOnInit():any{
        //jQuery(this._elementRef.nativeElement).find('#danmup').danmuplayer({
        //   'src':'https://sec.ch9.ms/ch9/ad03/33a90710-0d66-4c48-8f7f-db974771ad03/WSFLArchitectureDeepuThomas_high.mp4'  
        //});
        this.player = jQuery(this._elementRef.nativeElement).find('#danmup');
    }
    
    submitUrl(url:string){
        var self = this;
        this.bilibili.getVideos(url,
            result=>{
                self.av = result;
            });
    }
    
    openP(item:PItem){
        this.player.DanmuPlayer({
           src:item.Mp4Url 
        });
    }
}